package org.xx.armory.swing.builders;

import org.xx.armory.objectparser.LineInfo;

import java.util.List;

import static java.util.Arrays.asList;
import static org.xx.armory.commons.Validators.notNull;

public class SplitPaneModel
        extends AbstractComponentModel
        implements ComponentModel, ContainerModel {
    /**
     * 分隔条默认靠第一个组件。
     */
    public static final int DIVIDER_FIRST = 0;
    /**
     * 分隔条默认居中。
     */
    public static final int DIVIDER_CENTER = 1;
    /**
     * 分隔条默认靠第二个组件。
     */
    public static final int DIVIDER_LAST = 2;

    private final int axis;
    private final int dividerLocation;
    private final ComponentModel first;
    private final ComponentModel last;

    /**
     * 构造解析对象。
     *
     * @param lineInfo
     *         源文件中的位置信息。
     */
    protected SplitPaneModel(
            LineInfo lineInfo,
            String name,
            boolean visible,
            int axis,
            int dividerLocation,
            ComponentModel first,
            ComponentModel last
    ) {
        super(lineInfo, name, visible);

        this.axis = axis;
        if (dividerLocation != DIVIDER_FIRST && dividerLocation != DIVIDER_CENTER && dividerLocation != DIVIDER_LAST) {
            throw new IllegalArgumentException("dividerLocation should be DIVIDER_FIRST, DIVIDER_CENTER or DIVIDER_LAST");
        }
        this.dividerLocation = dividerLocation;
        this.first = notNull(first, "first");
        this.last = notNull(last, "last");
    }

    public int getAxis() {
        return this.axis;
    }

    public int getDividerLocation() {
        return this.dividerLocation;
    }

    public ComponentModel getFirst() {
        return this.first;
    }

    public ComponentModel getLast() {
        return this.last;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<ComponentModel> getChildren() {
        return asList(this.first, this.last);
    }
}
